package com.example.mobile2121606110syc0409homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity8 extends AppCompatActivity {

    private TextView tvMainTitle8;
    private TextView tvMainTit81;
    private TextView tvMainTit82;
    private TextView tvMainTit83;
    private EditText edtTtPN8;
    private Button btnMain8;
    private TextView tvMainTit84;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main8);
        initView();
        btnMain8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                double a = Double.parseDouble(edtTtPN8.getText().toString());
                double b = 0;
                if (a <= 100000){
                    b =  a * 0.1;
                    tvMainTit84.setText(String.format("%.2f", b));
                }else if (a>100000 && a<=200000){
                    b = ((a-100000)*0.075)+10000;
                    tvMainTit84.setText(String.format("%.2f", b));
                }else if (a>200000 && a<=400000){
                    b = ((a-200000)*0.05)+10000+7500;
                    tvMainTit84.setText(String.format("%.2f", b));
                }else if (a>400000 && a<=600000){
                    b = ((a-400000)*0.03)+10000+7500+5000;
                    tvMainTit84.setText(String.format("%.2f", b));
                }else if (a>600000 && a<=1000000){
                    b = ((a-600000)*0.015)+10000+7500+5000+3000;
                    tvMainTit84.setText(String.format("%.2f", b));
                }else if (a>1000000) {
                    b = ((a - 1000000) * 0.01) + 10000 + 7500 + 5000 + 3000 + 1500;
                    tvMainTit84.setText(String.format("%.2f", b));
                }
            }
        });
    }

    private void initView() {
        tvMainTitle8 = (TextView) findViewById(R.id.tvMainTitle8);
        tvMainTit81 = (TextView) findViewById(R.id.tvMainTit81);
        tvMainTit82 = (TextView) findViewById(R.id.tvMainTit82);
        tvMainTit83 = (TextView) findViewById(R.id.tvMainTit83);
        edtTtPN8 = (EditText) findViewById(R.id.edtTtPN8);
        btnMain8 = (Button) findViewById(R.id.btnMain8);
        tvMainTit84 = (TextView) findViewById(R.id.tvMainTit84);
    }
}